import 'package:hxdj/common/base_page/base_page.dart';
import 'package:hxdj/home/locationManager/location_manager.dart';
import 'package:amap_flutter_search/amap_flutter_search.dart';

class LocaAddressViewModel extends BaseViewModel {
  List<AMapPoiModel> dataList = [];
  List<AMapPoiModel> defaultDataList = [];

  //默认搜索附近的位置
  defaultSearch() async {
    String? city = LocationManager.result!["city"] as String?;
    String? latitude = LocationManager.result!["latitude"] as String?;
    String? longitude = LocationManager.result!["longitude"] as String?;
    String type = "酒店|小区|宾馆|街道|街区|商店|美食";
    // 搜索城市内POI
    List<AMapPoiModel> resultList = await MethodChannelAmapFlutterSearch().searchCityPoi(
        {"keyword": "", "city": city, "page": "", "latitude": latitude, "longitude": longitude, "types": type});
    defaultDataList.clear();
    defaultDataList.addAll(resultList);
    notifyListeners();
  }

  //搜索位置
  searchLocation(String keyword) async {
    String? city = LocationManager.result!["city"] as String?;
    String? latitude = LocationManager.result!["latitude"] as String?;
    String? longitude = LocationManager.result!["longitude"] as String?;
    dataList.clear();
    for (var i = 0; i < 4; i++) {
      // 搜索城市内POI
      List<AMapPoiModel> resultList = await MethodChannelAmapFlutterSearch().searchCityPoi({
        "keyword": keyword,
        "city": city,
        "page": (i).toString(),
        "latitude": latitude,
        "longitude": longitude,
      });
      dataList.addAll(resultList);
    }
 
    notifyListeners();
  }
}
